<template>
  <div>
    <div class="yearSelect">
      <a-select
        v-model="declarationSystemId"
        :allowClear="true"
        placeholder="请选择申报体系"
        style="width: 300px"
        @change="getData()"
      >
        <a-select-option v-for="item in systemList" :key="item.id" :value="item.id">{{ item.name }}</a-select-option>
      </a-select>
    </div>
    <a-row class="tList" type="flex" justify="start">
      <!-- <a-col :sm="24" :md="12" :xl="5" class="tItem">
        <div class="cardBox card1">
          <div class="key">累计申报体系</div>
          <div class="value">{{ detail.declarationInfoCount || 0 }}例</div>
        </div>
      </a-col> -->
      <a-col :sm="24" :md="12" :xl="5" class="tItem">
        <div class="cardBox card2">
          <div class="key">累计申报组织数</div>
          <div class="value">{{ detail.declarationInfoCount || 0 }}家</div>
        </div>
      </a-col>
      <a-col :sm="24" :md="12" :xl="5" class="tItem">
        <div class="cardBox card3">
          <div class="key">通过评估数</div>
          <div class="value">{{ detail.passCount || 0 }}家</div>
        </div>
      </a-col>
    </a-row>
    <a-card title="级别统计" :bordered="false">
      <a-row class="sList" type="flex" justify="start" v-if="detail.levels && detail.levels.length > 0">
        <a-col
          :sm="12"
          :md="6"
          :xl="4"
          class="sItem"
          v-for="item in detail.levels"
          :key="item.id">
          <div class="sBox">
            <div class="head">{{ item.name }}</div>
            <div class="body">
              <div class="left">
                <div class="key">{{ item.value.count }}</div>
                <div class="value">申报总数</div>
              </div>
              <div class="right">
                <div class="key">{{ item.value.pass }}</div>
                <div class="value">通过总数</div>
              </div>
            </div>
          </div>
        </a-col>
      </a-row>
      <div v-else>
        <a-empty />
      </div>
    </a-card>
    <a-row :gutter="24" type="flex" :style="{ marginTop: '24px' }">
      <a-col :xl="24" :md="24" :sm="24" >
        <a-card title="总分排行" :bordered="false">
          <div class="rank">
            <div class="top">
              <div
                class="btn"
                :class="item.id === levelId ? 'active': ''"
                v-for="item in detail.levels"
                :key="item.id"
                @click="changeRank(item.id)"
              >{{ item.name }}</div>
            </div>
            <a-table
              :rowKey="(record) => record.declarationInfoId"
              :columns="columns"
              :data-source="levelData"
              :pagination="false"
              :scroll="{ y: 370 }"
            >
              <span slot="serial" slot-scope="text, record, index">
                {{ index + 1 }}
              </span>
            </a-table>
          </div>
        </a-card>
      </a-col>
      <!-- <a-col :xl="14" :md="24" :sm="24">
        <a-card title="申报体系数据" :bordered="false">
          <div class="data">
            <a-table
              :rowKey="(record) => record.id"
              :columns="systemColumns"
              :data-source="detail.declarationSystemList"
              :pagination="{ pageSize: 50 }"
              :scroll="{ y: 300 }"
            >
              <span slot="dateRange" slot-scope="text, record">
                {{ record.startDate }}-{{ record.endDate }}
              </span>
            </a-table>
          </div>
        </a-card>
      </a-col> -->
    </a-row>
  </div>
</template>

<script>
import { getData, getRanking } from '@/api/home'
import { getSystem } from '@/api/system'
const columns = [
   {
    title: '排行',
    scopedSlots: { customRender: 'serial' }
  },
  {
    title: '社会组织',
    dataIndex: 'userName'
  },
  {
    title: '组织类别',
    dataIndex: 'type'
  },
  {
    title: '总分',
    dataIndex: 'score'
  }
]

const systemColumns = [
  {
    title: '名称',
    dataIndex: 'name'
  },
  {
    title: '数量',
    dataIndex: 'declarationNum'
  },
  {
    title: '时间段',
    dataIndex: 'dateRange',
    width: 200,
    scopedSlots: { customRender: 'dateRange' }
  }
]
export default {
  name: 'Home',
  components: {
  },
  data () {
    return {
      systemList: [],
      declarationSystemId: '',
      detail: {},
      levelData: [],
      levelId: '',
      columns,
      systemColumns
    }
  },
  created () {
    this.getSystemList()
  },
  methods: {
    getSystemList () {
      getSystem({
        current: 1,
        size: 10000
      }).then(res => {
        this.systemList = res.records
        if (this.systemList.length > 0) {
          const cur = this.systemList.find(item => item.status === 2 || item.status === 3 || item.status === 4)
          if (cur) {
            this.declarationSystemId = cur.id
          } else {
            this.declarationSystemId = this.systemList[0].id
          }
          this.getData()
        }
      })
    },
    getData () {
      getData({
        declarationSystemId: this.declarationSystemId
      }).then(res => {
        this.detail = res
        if (res.levels.length > 0) {
          this.levelId = res.levels[0].id
          this.getRanking()
        } else {
          this.levelData = []
        }
      })
    },
    getRanking () {
      getRanking({
        declarationSystemId: this.declarationSystemId,
        levelId: this.levelId
      }).then(res => {
        this.levelData = res
      })
    },
    changeRank (id) {
      this.levelId = id
      this.getRanking()
    }
  }
}
</script>

<style lang="less" scoped>
.yearSelect {
  position: absolute;
  top: 24px;
  right: 24px;
}
.tList {
  background-color: #fff;
  margin-bottom: 24px;
  .tItem {
    padding: 24px;
  }
  .cardBox {
    width: 100%;
    height: 137px;
    border-radius: 9px;
    overflow: hidden;
    &.card1 {
      background: linear-gradient(90deg, #FFD198 0%, #FF858F 100%);
      box-shadow: 3px 3px 12px 0px rgba(228,228,228,0.5);
    }
    &.card2 {
      background: linear-gradient(90deg, #FFD9A8 0%, #FDA43A 100%);
      box-shadow: 3px 3px 12px 0px rgba(228,228,228,0.5);
    }
    &.card3 {
      background: linear-gradient(90deg, #B1CBFF 1%, #6DA0FF 100%);
      box-shadow: 3px 3px 12px 0px rgba(228,228,228,0.5);
    }
    .key {
      margin: 33px 0 5px 51px;
      font-size: 18px;
      font-weight: 400;
      color: #FFFFFF;
      text-shadow: 0px 3px 4px rgba(215,4,22,0.55);
    }
    .value {
      margin-left: 51px;
      font-size: 30px;
      font-weight: 400;
      color: #FFFFFF;
      text-shadow: 0px 3px 4px rgba(210,33,44,0.4);
    }
  }
}
.sList {
  margin: -24px;
  .sItem {
    padding: 24px;
    .sBox {
      width: 100%;
      height: 130px;
      border: 1px solid #E9E9E9;
      border-radius: 12px;
      overflow: hidden;
      .head {
        width: 100%;
        height: 43px;
        background: #EDF3FF;
        font-size: 20px;
        color: #0084FE;
          .flex-center();
      }
      .body {
        width: 100%;
        height: 85px;
        .flex-between();
        .left, .right {
          width: 50%;
          height: 100%;
          .flex-center-vertical();
          .key {
            font-size: 20px;
            color: #333333;
          }
          .value {
            font-size: 14px;
            color: #999999;
          }
        }
        .left {
        position: relative;
          &::after {
            content: '';
            position: absolute;
            top: 21px;
            right: 0;
            width: 2px;
            height: 43px;
            background: #E0E0E0;
            border: 1px solid #F0F0F0;
          }
        }
      }
    }
  }
}
.rank {
  width: 100%;
  .top {
    .flex-start();
    margin-bottom: 24px;
    .btn {
      width: 100px;
      height: 40px;
      font-size: 14px;
      color: #000000;
      background: #FAFAFA;
      border-radius: 4px 4px 0px 0px;
      margin-right: 5px;
      cursor: pointer;
      .flex-center();
      &.active {
        background: #F3F9FF;
        color: #1890FF;
      }
    }
  }
}
</style>
